﻿<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head><link rel="stylesheet" href="${ctx}/common/common.css">
    <title>Title</title>
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="${ctx}/common/plugins/layuiadmin/style/admin.css" media="all">
    <script src="${ctx}/common/plugins/layuiadmin/layui/layui.js"></script>
    
</head>
<body>
<!--主体内容层-->
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12 layui-col-space15">
            <form>
                <!--输入框内容盒子-->
                <div class="layui-col-md12">

                    <!--输入框-->
                    <div class="layui-col-md4">
                        <label class="layui-form-label">行业类别名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="industryCategoryName" id="industryCategoryName" required lay-verify="required"
                                   placeholder="请输入行业类别名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <!--数字框-->
                    <div class="layui-col-md4">
                        <label class="layui-form-label">行业类别编码</label>
                        <div class="layui-input-block">
                            <input type="text" name="industryCategoryCode" id="industryCategoryCode" required lay-verify="required"
                                   placeholder="请输入行业类别编码" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <!--输入框-->
                    <div class="layui-col-md4">
                        <label class="layui-form-label">上级行业类别名称</label>
                        <div class="layui-input-block">
                            <input type="text" name="industryCategoryParentName" required id="industryCategoryParentName" lay-verify="required"
                                   placeholder="请输入上级行业类别名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                </div>

                <!--通用按钮盒子-->
                <div class="layui-col-md12">
                    <div style="float: right;" class="paramBtn">
                        <button data-type="reloadIndustryCategory" type="button" class="layui-btn layui-btn-sm layui-btn-danger">
                            查询
                        </button>
                        <button data-type="resetIndustryCategory" type="reset" class="layui-btn layui-btn-sm layui-btn-danger">
                            重置
                        </button>
                    </div>
                </div>
            </form>
            <!--通用table表格-->
            <div class="layui-btn-group demoTable">
                <button class="layui-btn layui-btn-sm" data-type="addIndustryCategory">
                    <i class="layui-icon">&#xe654;</i>
                </button>
                <!--删除-->
                <button class="layui-btn layui-btn-sm" data-type="delIndustryCategorySelect">
                    <i class="layui-icon">&#xe640;</i>
                </button>
            </div>
            <table class="layui-table" id="industryCategoryReload" lay-data="{ url:'/industryCategory/findIndustryCategoryPage', page:true,groups:5}"
                   lay-filter="demo">
                <thead>
                <tr>
                    <th lay-data="{type:'checkbox', fixed: 'left'}"></th>
                    <th lay-data="{field:'name',sort:true,width:180}">行业类别名称</th>
                    <th lay-data="{field:'code',sort:true,width:180}">行业类别编码</th>
                    <th lay-data="{field:'sex',sort:true,width:180}">上级行业类别名称</th>
                    <th lay-data="{field:'creator_name',sort:true,width:180}">创建人</th>
                    <th lay-data="{field:'create_time',sort:true,templet:'#createTime'}">创建时间</th>
                    <th lay-data="{field:'right',toolbar:'#barDemo'}">操作</th>
                </tr>
                </thead>
            </table>
        </div>
    </div>
</div>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-sm" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-sm" lay-event="del">删除</a>
</script>
<script id="createTime" type="text/html">
    {{#
        var date = new Date();
        date.setTime(d.create_time);
        return date.Format("yyyy-MM-dd hh:mm:ss");
    }}
</script>
</body>
<script>

    layui.use('table', function () {
        var loading=layer.msg("数据加载中...");
        var table = layui.table;
        table.render({
            done:function(){
                layer.close(loading);
            }
        })
        //监听filter为demo的table中的工具条
        table.on('tool(demo)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                window.location.href = '${ctx}/industryCategory/industryCategoryEditPage?industryCategoryId=' + obj.data.id
            } else if (obj.event === 'del') {
                layer.confirm('确认删除?', function (index) {
                    obj.del();
                    layer.close(index);
                    $.post("${ctx}/industryCategory/delIndustryCategory", {industryCategoryId: obj.data.id}, function (data) {
                        if (data == 'success') {
                            layer.alert("删除成功");
                            table.reload('industryCategoryReload', {
                                where: {
                                	industryCategoryName: '',
                                	industryCategoryCode: '',
                                	industryCategoryParentName: '',
                                }
                            })
                        } else {
                            layer.alert("删除失败");
                        }
                    }, "text")

                });
            } else if (obj.event === 'edit') {
                window.location.href = '${ctx}/industryCategory/industryCategoryEditPage?industryCategoryId=' + obj.data.id
            }
        });

        var $ = layui.$, active = {
            reloadIndustryCategory: function () {//条件查询
                var industryCategoryName = document.getElementById("industryCategoryName").value;
                var industryCategoryCode = document.getElementById("industryCategoryCode").value;
                var industryCategoryParentName = document.getElementById("industryCategoryParentName").value;
                table.reload('industryCategoryReload', {
                    where: {
                    	industryCategoryName: industryCategoryName,
                    	industryCategoryCode: industryCategoryCode,
                    	industryCategoryParentName: industryCategoryParentName,
                    }
                });
            },
            resetIndustryCategory: function () {
                table.reload('industryCategoryReload', {
                    where: {
                    	industryCategoryName: '',
                    	industryCategoryCode: '',
                    	industryCategoryParentName: '',
                    }
                })
            },
            addIndustryCategory: function () {
                window.location.href = '${ctx}/industryCategory/industryCategoryEditPage'
            },
            delIndustryCategorySelect: function () {
                var checkStatus = table.checkStatus('industryCategoryReload')
                var ids='';
                var data = checkStatus.data;
                for (var i in data){
                    ids+=data[i].id+",";

                }
                $.post("${ctx}/industryCategory/delIndustryCategories", {industryCategoryIds: ids}, function (data) {
                    if (data == 'success') {
                        layer.alert("删除成功");
                        table.reload('industryCategoryReload', {
                            where: {
                            	industryCategoryName: '',
                            	industryCategoryCode: '',
                            	industryCategoryParentName: '',
                            }
                        })
                    } else {
                        layer.alert("删除失败");
                    }
                }, "text")
            }


        };

        $('.demoTable .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        //给按钮绑定active中的方法
        $(".paramBtn .layui-btn").on("click", function () {
            var type = $(this).data('type');
            //查看是active这个json中是否有type这个方法，如果有调用，如果没有不知心；
            active[type] ? active[type].call() : '';
        })

    });

    Date.prototype.Format = function(fmt) { //author: meizz
        if(this=='Invalid Date'){
            return '';
        }
        var o = {
            "M+" : this.getMonth()+1,                 //月份
            "d+" : this.getDate(),                    //日
            "h+" : this.getHours(),                   //小时
            "m+" : this.getMinutes(),                 //分
            "s+" : this.getSeconds(),                 //秒
            "q+" : Math.floor((this.getMonth()+3)/3), //季度
            "S"  : this.getMilliseconds()             //毫秒
        };
        if(/(y+)/.test(fmt))
            fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length));
        for(var k in o)
            if(new RegExp("("+ k +")").test(fmt))
                fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length)));
        return fmt;
    }
</script>
</html>



